package com.aicheyoudao;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.concurrent.TimeoutException;

import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.message.BasicNameValuePair;

import com.aicheyoudao.utils.HttpUtils;

import android.content.Context;
import android.os.AsyncTask;

public class MyAsyncTask extends AsyncTask<String, Integer, String> {
	private onloadlistener listener;
	private Context context;

	public MyAsyncTask(Context context) {
		this.context = context;
	}

	@Override
	protected String doInBackground(String... params) {
		String url = "http://121.40.143.106:8080/DianShang/servlet/MyinfoMapServlet";
		NameValuePair arg = new BasicNameValuePair("shopname", params[0]);
		HashMap<String, Object> res = null;
		
			try {
				res = HttpUtils.httpPost(url, arg);
			} catch (ConnectTimeoutException e) {
				e.printStackTrace();
			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} catch (UnknownHostException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (TimeoutException e) {
				e.printStackTrace();
			}
		
		return (String) res.get(HttpUtils.HTTP_KEY_CONTENT);
	}

	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		MyLoadingDialog.stopDialog();
		listener.loadFinish(result);
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		MyLoadingDialog.StartShowProgressDialog(context);

	}

	public void setOnloadlistener(onloadlistener lis) {
		this.listener = lis;
	}

	public interface onloadlistener {
		public void loadFinish(String res);
	}
}
